<?php
require ('includes/config.php');
$page_title = 'Events';
include ('includes/header.php');

if ($_SERVER['REQUEST_METHOD'] == 'POST'){
	$keyword = $_POST['keyword'];
$searchfield = $_POST['searchfield'];	
	}
  
  
  
   
?>
 <!-- fluid body container -->

<div class="container-fluid">
<!--fluid sidebar 3 columns   -->
	<div class="span3">
		<div class="well sidebar-nav">
<?php
require ('includes/side_nav_events.php');
?>
         </div>
    </div>
   <!---end of sidebar 3 columns  -->
  
  <div class="span9">
  		<div class="hero-unit">
        
   <form class = "form-search"id="searchform" name="searchform" method="post" action="Events.php">
<label><b>Search:</b></label>
<input type="hidden" value="search" name="submitted">
<input type="text" title="Enter search text" size="12" name="keyword" value="" alt="search">
<select name = "searchfield">
<option value = "text">Event Name</option>
<option value="start_date">Event Date</option>
<option value="type">Event Type</option>
</select>
<input class = "btn-large btn-primary" type="submit" title="Click to search our site for products etc" value="GO" name="goButton" style="margin:0px;padding:0px;">
</form>
 <?php require(MYSQL);  //open database        
if (isset($keyword)){		
            //Search for comments which contain a keyword
			$q=" SELECT `ev_id`,`text`,`start_date`,`type` FROM `events`  WHERE $searchfield LIKE '%$keyword%' ORDER BY start_date";
$r = mysqli_query ($dbc, $q);
 

            echo "Search for keyword <strong>$keyword</strong> :<br/><br/>";
  
}
else{
   $q="SELECT `ev_id`,`text`,`start_date`,`type` FROM `events` ORDER BY  start_date";//to print out all events
}

   $r = mysqli_query ($dbc, $q);
   echo '<table border="0" width="95%" cellspacing="3" cellpadding="3" align="center">
	<tr>
		<td align="left" width="5%"><b>ID</b></td>
		<td align="left" width="25%"><b>Event date</b></td>
		<td align="left" width="35%"><b>Description</b></td>
		<td align="left" width="15%"><b>Category</b></td>
		<td align="left" width="10%"></td>
		<td align="left" width="10%"></td>
	</tr>';
   
   while ($row = mysqli_fetch_array ($r, MYSQLI_ASSOC)) {
   echo "\t<tr>	
		<td align=\"left\"><a href=\"index.php\"> {$row['ev_id']}</td>
		<td align=\"left\">{$row['start_date']}</td>
		<td align=\"left\">{$row['text']}</td>
		<td align=\"left\">{$row['type']}</td>
		<td align=\"left\"><a href=\"delete.php?eid={$row['ev_id']}\">Delete</td>
		<td align=\"left\"><a href=\"ammend.php?eid={$row['ev_id']}\">Amend</td>
	</tr>\n";
		

} // End of while loop.

echo '</table>';

   ?>
   		 </div>
  <!--end of hero-unit -->
  <!--start of events list -->
  		  <div class="row-fluid">This is where the events list will go
 		   </div>
    </div>
  <!--end of events list -->
<!-- start of left bar to do list -->
 	
    </div>
    <!-- end of to do list-->
    </div>
    <script src="http://code.jquery.com/jquery-latest.js"></script>
    <script src="js/bootstrap.min.js"></script>
	<script src="js/bootstrap.js"></script>
  </body>
</html>
<?php ob_flush(); ?>
